"""
File: search_page.py
Author: ershixiong
Date: 2023/11/22
describe:

"""
from selenium import webdriver
from selenium.webdriver.common.by import By


class SearchPage:
    __INPUT_SEARCH = (By.NAME, 'q')
    __BUTTON_SEARCH = (By.CSS_SELECTOR, '.Header_nav__search__addon_2nk')

    def __init__(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(3)
        self.driver.get('https://xueqiu.com/')

    def search_stock(self, stock_name: str):
        self.__SPAN_STOCK = (By.XPATH, f'//*[text()="{stock_name}"]')

        self.driver.find_element(*self.__INPUT_SEARCH).send_keys(stock_name)
        self.driver.find_element(*self.__BUTTON_SEARCH).click()
        name = self.driver.find_element(*self.__SPAN_STOCK).text
        return name
